﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;
using System.Drawing;

namespace HZ.DrugTrade.Web.Admin.SystemManage
{
    public partial class ComInfoModify : BasePage
    {
         protected string strType = "经营";
        protected string strGMPorGSP = "GSP";

        public ComInfoModify()
        {
            this.ModuleNo = Module.系统管理.ToString();
            this.PageOperateType = OperateType.企业管理.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            
            //绑定企业的基本信息
            if (!IsPostBack)
            {
                string comId = Request.QueryString["comid"].ToString();
               // string cuserID= CurrentAccount.GetUser().Org.OrgID;
                IBLL_Company companyCtrl = Factory.BLL_Company();
                HZ.DrugTrade.Model.CompanyInfo compinfo = companyCtrl.GetCompanyInfoByID(comId);
                //bool IsSc = companyCtrl.IsSCCompany(cuserID);
                //if (compinfo.CheckStatus==1)//若审核通过
                //{
                //    this.lblCkState.Text = "--中心审核已通过";
                //    this.lblCkState.ForeColor = Color.Green;
                //    this.btnSave.Visible = false;
                //}
                //else if (compinfo.CheckStatus==2)
                //{
                //    this.lblCkState.Text = "--中心审核未通过("+compinfo.CheckReason+")";
                //    this.lblCkState.ForeColor = Color.Red;
                //}
                //else
                //{
                //    this.lblCkState.Text = "--中心未审核";

                //}
                //if (IsSc)
                //{
                //    this.lblCkState.Visible = false;
                //}
                //if (compinfo==null)
                //{
                //     PageError("信息缺失！", "");
                //}
                //if (CurrentAccount.GetUser().UserRole.RoleID == "05")
                //{
                //    strType = "生产";
                //    strGMPorGSP = "GMP";

                //}
                //else
                //{
                //    strType = "经营";
                //    strGMPorGSP = "GSP";
                //}
                lblcompanyname.Text = compinfo.CompanyName;//企业名称
                lblSort.Text = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetComType(comId);//企业类型
                lblContactPerson.Text = compinfo.ContactPerson;//企业联系人
                txtComTel.Text = compinfo.TelNo;//企业联系电话
                txtCellNo.Text = compinfo.CellNo;//企业联系人手机
                txtLayMan.Text = compinfo.LayMan;//法人名称
                txtAddress.Text = compinfo.Address;//企业地址
                txtBusinessCertificate.Text = compinfo.BusinessCertificate;//生产或经营许可证号
                txtFax.Text = compinfo.Fax;//企业传真
                txtEmail.Text = compinfo.Email;//电子邮箱
                txtBusinessCertificateDate.Text = (compinfo.BusinessCertificateDate != null) ? compinfo.BusinessCertificateDate.Value.ToString("yyyy-MM-dd") : "";//生产或经营许可证有效期
                txtPostCode.Text = compinfo.PostCode;//邮政编码
                txtPermission.Text = compinfo.Permission;//营业执照号
                txtPermissionDate.Text = (compinfo.PermissionDate != null) ? compinfo.PermissionDate.Value.ToString("yyyy-MM-dd") : "";//营业执照有限期
                txtPermissionCheckDate.Text = (compinfo.PermissionCheckDate != null) ? compinfo.PermissionCheckDate.Value.ToString("yyyy-MM-dd") : "";//营业执照年检日期
                txtComcode.Text = compinfo.Comcode;//企业组织机构代码证号
                txtComEndTime.Text = (compinfo.ComEndtime != null) ? compinfo.ComEndtime.Value.ToString("yyyy-MM-dd") : "";//企业代码证有效期
                txtRegistAddress.Text = compinfo.RegistAddress;//企业注册地址
                txtRegistFund.Text = compinfo.RegisterFund.ToString();//企业注册资金
                txtAuthor.Text = compinfo.Author;//企业被授权人
                txtAuhtorCell.Text = compinfo.AuthorCell.ToString();//被授权人手机
                txtStorHouseAddress.Text = compinfo.StoreHouseAddress;//企业仓库地址
                txtInstruments.Text = compinfo.Instruments;//医疗器械许可证号
                if (compinfo.Permissionloogtime == 1)
                {
                    chkBusinessDate.Checked = true;
                    isshow.Visible = false;
                }
                if (compinfo.Businessloogtime == 1)
                {
                    this.ckBusinessCertificateDate.Checked = true;
                    isshows.Visible = false;
                }
                if (compinfo.Devious == "是")
                {
                    rbtnDevious.SelectedIndex = 0;
                }
                if (compinfo.Adulterant == "有")
                {
                    rbtnAdulterant.SelectedIndex = 0;
                }
                //txtWebsite.Text=compinfo.Website;
                //txtGSPCode.Text=compinfo.GSPCode;
                //txtGSPTime.Text = (compinfo.GSPTime != null)?compinfo.GSPTime.Value.ToString("yyyy-MM-dd"):"";
                txtBusinessRange.Text = compinfo.BusinessRange;
                txtRemarks.Text = compinfo.Remarks;

            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
             HZ.DrugTrade.Model.CompanyInfo compinfo = new HZ.DrugTrade.Model.CompanyInfo();
            compinfo.CompanyName = lblcompanyname.Text.Trim();//企业名称
            compinfo.TelNo = txtComTel.Text.Trim();//联系电话
            compinfo.ContactPerson = lblContactPerson.Text.Trim();//联系人
            compinfo.CellNo = txtCellNo.Text.Trim();//联系人手机
            compinfo.LayMan = txtLayMan.Text.Trim();//法人名称
            compinfo.Address = txtAddress.Text.Trim();//联系地址
            compinfo.BusinessCertificate = txtBusinessCertificate.Text.Trim();//许可证号
            compinfo.BusinessCertificateDate = new HZ.Common.ConvertHelper(txtBusinessCertificateDate.Text.Trim()).ToDateTime;//许可证有效期
            compinfo.Fax = txtFax.Text.Trim();//传真
            compinfo.Author = txtAuthor.Text;//企业被授权人
            compinfo.AuthorCell = txtAuhtorCell.Text;//被授权人手机
            compinfo.Comcode = txtComcode.Text;//企业组织机构代码证号
            compinfo.ComEndtime = new HZ.Common.ConvertHelper(txtComEndTime.Text.Trim()).ToDateTime;//组织机构代码证有效期
            compinfo.RegistAddress = txtRegistAddress.Text;//企业注册地址
            compinfo.RegisterFund = new HZ.Common.ConvertHelper(txtRegistFund.Text.Trim()).ToDouble;//企业注册资金
            compinfo.StoreHouseAddress = txtStorHouseAddress.Text;//仓库地址
            compinfo.Permission = txtPermission.Text;//营业执照号
            compinfo.PermissionDate = new HZ.Common.ConvertHelper(txtPermissionDate.Text.Trim()).ToDateTime;//营业执照有效期
            compinfo.PermissionCheckDate = new HZ.Common.ConvertHelper(txtPermissionCheckDate.Text.Trim()).ToDateTime;//营业执照年检日期
            compinfo.PostCode = txtPostCode.Text;//邮政编码
            compinfo.BusinessRange = txtBusinessRange.Text.Trim();//生产或经营范围
            compinfo.Email = txtEmail.Text;//电子邮箱
            compinfo.Devious = rbtnDevious.SelectedValue;//是否有经营不良行为
            compinfo.Adulterant = rbtnAdulterant.SelectedValue;//两年内有无生产假劣药记录
            compinfo.Instruments = txtInstruments.Text.Trim();//医疗器械许可证号
            compinfo.Remarks = txtRemarks.Text.Trim();//备注
            compinfo.IsSubmit = 1;

            if (this.chkBusinessDate.Checked == true)
            {
                compinfo.Permissionloogtime = 1;
            }
            else
            {
                compinfo.Permissionloogtime = 0;
            }
            if (this.ckBusinessCertificateDate.Checked == true)
            {
                compinfo.Businessloogtime = 1;
            }
            else
            {
                compinfo.Businessloogtime = 0;
            }
            IBLL_Company companyCtrl = Factory.BLL_Company();
            //保存设置
            if (companyCtrl.UpdateCompanyInfo(compinfo) == 1)
            {
                PageInfo("保存成功！", "");
            }
            else
            {
                PageError("保存失败！", "");
            }
        
        }

        protected void chkBusinessDate_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chkBusinessDate.Checked == true)
            {
                isshow.Visible = false;
                this.txtPermissionDate.Text = "2999-12-31";
            }
            else
            {
                isshow.Visible = true;
                this.txtPermissionDate.Text = "";
            }
        }

        protected void ckBusinessCertificateDate_CheckedChanged(object sender, EventArgs e)
        {
            if (this.ckBusinessCertificateDate.Checked == true)
            {
                isshows.Visible = false;
                this.txtBusinessCertificateDate.Text = "2999-12-31";
            }
            else
            {
                isshows.Visible = true;
                this.txtBusinessCertificateDate.Text = "";
            }
        }
    }
}
